package com.zrwl.poscloud.core.restapi.admin.authority;

import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.AdminRoleService;
import com.zrwl.poscloud.xo.vo.AdminRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员权限管理 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-04-22
 */
@RestController
@Api(value = "管理员权限管理相关接口", tags = {"管理员权限管理相关接口"})
@RequestMapping("/adminRole")
@Slf4j
public class AdminRoleRestApi {
    @Autowired
    private AdminRoleService adminRoleService;

    @AuthorityVerify
    @ApiOperation(value = "获取管理员权限管理列表", notes = "获取管理员权限管理列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody AdminRoleVO adminRoleVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取管理员权限管理列表: {}", adminRoleVO);
        return ResultUtil.successWithData(adminRoleService.getPageList(adminRoleVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取管理员权限管理列表", notes = "获取管理员权限管理列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody AdminRoleVO adminRoleVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取管理员权限管理列表: {}", adminRoleVO);
        return ResultUtil.successWithData(adminRoleService.getAllList(adminRoleVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增管理员权限管理")
    @ApiOperation(value = "新增管理员权限管理", notes = "新增管理员权限管理", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody AdminRoleVO adminRoleVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增管理员权限管理: {}", adminRoleVO);
        return adminRoleService.add(adminRoleVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改管理员权限管理")
    @ApiOperation(value = "修改管理员权限管理", notes = "修改管理员权限管理", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody AdminRoleVO adminRoleVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改管理员权限管理: {}", adminRoleVO);
        return adminRoleService.edit(adminRoleVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除管理员权限管理")
    @ApiOperation(value = "删除管理员权限管理", notes = "删除管理员权限管理", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody AdminRoleVO adminRoleVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除管理员权限管理: {}", adminRoleVO);
        return adminRoleService.delete(adminRoleVO);
    }

    @AuthorityVerify
    @ApiOperation(value = "获取用户权限列表", notes = "获取用户权限列表", response = String.class)
    @PostMapping("/getadminRoleList")
    public String getadminRoleList(@RequestBody AdminRoleVO adminRoleVO) {
        log.info("获取用户权限列表: {}", adminRoleVO);
        return ResultUtil.successWithData(adminRoleService.getadminRoleList(adminRoleVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "用户权限开关")
    @ApiOperation(value = "用户权限开关", notes = "用户权限开关", response = String.class)
    @PostMapping("/adminRoleSwitch")
    public String adminRoleSwitch(@RequestBody AdminRoleVO adminRoleVO) {
        log.info("用户权限开关: {}", adminRoleVO);
        return adminRoleService.adminRoleSwitch(adminRoleVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "获取超管管辖的分配权限列表")
    @ApiOperation(value = "获取超管管辖的分配权限列表", notes = "获取超管管辖的分配权限列表")
    @PostMapping("/getSuperAdminRoleList")
    public String getSuperAdminRoleList(@RequestBody AdminRoleVO adminRoleVO) {
        return ResultUtil.successWithData(adminRoleService.getSuperAdminRoleList(adminRoleVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "超管管理权限开关")
    @ApiOperation(value = "超管管理权限开关", notes = "超管管理权限开关", response = String.class)
    @PostMapping("/superAdminRoleSwitch")
    public String superAdminRoleSwitch(@RequestBody AdminRoleVO adminRoleVO) {
        log.info("超管管理权限开关: {}", adminRoleVO);
        return adminRoleService.superAdminRoleSwitch(adminRoleVO);
    }

}
